package net.cyl.config;

import lombok.Data;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * @author cyl
 * @date 2023-05-07 16:03
 * @description
 */
@Configuration
@Data
public class RabbitMQConfig {
    /**
     * 短链事件交换机
     */
    private String ShortLinkEventExchangeName = "short_link.event.exchange" ;

    /**
     * 创建短链事件交换机
     *
     * @return
     */
    @Bean
    public TopicExchange getShortLinkEventExchange() {

        return new TopicExchange(ShortLinkEventExchangeName,true,false);
    }
    /**
     * 短链事件队列
     */
    private String shortLinkAddLinkQueue="short_link.add.link.queue" ;

    private String shortLinkDeleteLinkQueue="short_link.delete.link.queue" ;

    private String shortLinkUpdateLinkQueue="short_link.update.link.queue" ;

    /**
     * 添加短链映射队列
     */
    private String shortLinkAddMappingQueue="short_link.add.mapping.queue" ;

    private String shortLinkDeleteMappingQueue="short_link.delete.mapping.queue" ;

    private String shortLinkUpdateMappingQueue="short_link.update.mapping.queue" ;

    /**
     * 短链事件路由键
     */
    private String shortLinkAddRoutingKey="short_link.add.link.mapping.routing.key" ;

    private String shortLinkDeleteRoutingKey="short_link.delete.link.mapping.routing.key" ;

    private String shortLinkUpdateRoutingKey="short_link.update.link.mapping.routing.key" ;
    /**
     * 短链事件绑定键
     */
    private String shortLinkAddLinkBindingKey="short_link.add.link.*.routing.key" ;

    private String shortLinkDeleteLinkBindingKey="short_link.delete.link.*.routing.key" ;

    private String shortLinkUpdateLinkBindingKey="short_link.update.link.*.routing.key" ;
    /**
     * 短链事件绑定键
     */
    private String shortLinkAddMappingBindingKey="short_link.add.*.mapping.routing.key" ;

    private String shortLinkDeleteMappingBindingKey="short_link.delete.*.mapping.routing.key" ;

    private String shortLinkUpdateMappingBindingKey="short_link.update.*.mapping.routing.key" ;

    /**
     * 创建短链事件队列
     * @return
     */
    @Bean
    public Binding shortLinkAddApiBinding() {
        return  new Binding(shortLinkAddLinkQueue, Binding.DestinationType.QUEUE, ShortLinkEventExchangeName, shortLinkAddLinkBindingKey, null);
    }

    @Bean
    public Binding shortLinkDeleteApiBinding() {
        return  new Binding(shortLinkDeleteLinkQueue, Binding.DestinationType.QUEUE, ShortLinkEventExchangeName, shortLinkDeleteLinkBindingKey, null);
    }

    @Bean
    public Binding shortLinkUpdateApiBinding() {
        return  new Binding(shortLinkUpdateLinkQueue, Binding.DestinationType.QUEUE, ShortLinkEventExchangeName, shortLinkUpdateLinkBindingKey, null);
    }
    /**
     * 创建短链事件队列
     * @return
     */
    @Bean
    public Binding shortLinkAddMappingBinding() {
        return  new Binding(shortLinkAddMappingQueue, Binding.DestinationType.QUEUE, ShortLinkEventExchangeName, shortLinkAddMappingBindingKey, null);
    }

    @Bean
    public Binding shortLinkDeleteMappingBinding() {
        return  new Binding(shortLinkDeleteMappingQueue, Binding.DestinationType.QUEUE, ShortLinkEventExchangeName, shortLinkDeleteMappingBindingKey, null);
    }

    @Bean
    public Binding shortLinkUpdateMappingBinding() {
        return  new Binding(shortLinkUpdateMappingQueue, Binding.DestinationType.QUEUE, ShortLinkEventExchangeName, shortLinkUpdateMappingBindingKey, null);
    }

    /**
     * 创建短链事件队列
     * @return
     */
    @Bean
    public Queue shortLinkAddLinkQueue() {
        return new Queue(shortLinkAddLinkQueue, true, false, false, null);
    }

    @Bean
    public Queue shortLinkDeleteLinkQueue() {
        return new Queue(shortLinkDeleteLinkQueue, true, false, false, null);
    }

    @Bean
    public Queue shortLinkUpdateLinkQueue() {
        return new Queue(shortLinkUpdateLinkQueue, true, false, false, null);
    }

    /**
     * 创建短链事件队列
     * @return
     */
    @Bean
    public Queue shortLinkAddMappingQueue() {
        return new Queue(shortLinkAddMappingQueue, true, false, false, null);
    }

    @Bean
    public Queue shortLinkDeleteMappingQueue() {
        return new Queue(shortLinkDeleteMappingQueue, true, false, false, null);
    }

    @Bean
    public Queue shortLinkUpdateMappingQueue() {
        return new Queue(shortLinkUpdateMappingQueue, true, false, false, null);
    }
}
